package com.example.algorithm.tree;

/**
 * @author : zhy
 * @since : 2022/8/8
 * 二叉树左路径和
 */
public class SumLeftTreePath {
    public int sumOfLeftLeaves(TreeNode root) {
       if(root==null){
           return 0;
       }
       int leftSum=sumOfLeftLeaves(root.left);
       int rightSum=sumOfLeftLeaves(root.right);
       int midSum=0;
       if(root.left!=null&&root.left.left==null&&root.left.right==null){
           midSum=root.left.val;
       }
       return midSum+leftSum+rightSum;
    }

    public static void main(String[] args) {
    }
}
